package com.xwli.springcloud.gof23.strategy;

import com.xwli.springcloud.gof23.strategy.behavior.impl.FlyRocketPowered;
import com.xwli.springcloud.gof23.strategy.subclass.MallardDuck;
import com.xwli.springcloud.gof23.strategy.subclass.ModelDuck;

/**
 * @author xwli
 * @date: 2022/2/25 10:33
 * @desc
 * @since JDK 1.8
 */
public class Test {
    public static void main(String[] args) {
        modelDuck();
    }

    /**
     * 依靠构造器去初始化飞行行为
     */
    private static void mallardDuck(){
        Duck mallardDuck = new MallardDuck();
        mallardDuck.performQuack();
        mallardDuck.swim();
        mallardDuck.performFly();
    }

    /**
     * 动态的去改变飞行行为
     */
    private static void modelDuck(){
        Duck modelDuck = new ModelDuck();
        modelDuck.performFly();
        modelDuck.setFlyBehavior(new FlyRocketPowered());
        modelDuck.performFly();
    }
}

